import com.cgah.Bid
import com.cgah.Customer
import com.cgah.Listing
import java.sql.Timestamp


class BootStrap {

    def init = { servletContext ->

        if (!Customer.count()) {
            Customer c1 = new Customer(emailAddress: "johndoe@test.com", password: "boooya", createdDate: new Date()).save(failOnError: true)
            Customer c2 = new Customer(emailAddress: "janedoe@test.com", password: "boooya", createdDate: new Date()).save(failOnError: true)

            if (!Listing.count()) {

                Listing l1 = new  Listing(name: "bling bling", startingBidPrice: 10.0, seller: c1, endDateTime: new Date() + 6, createdDateTime: new Date() - 6).save(failOnError: true);
                new  Listing(name: "silver bling", startingBidPrice: 9.0, seller: c1, endDateTime: new Date() + 5, createdDateTime: new Date() - 5).save(failOnError: true);
                new  Listing(name: "gold bling", startingBidPrice: 8.0, seller: c1, endDateTime: new Date() + 4, createdDateTime: new Date() - 4).save(failOnError: true);
                new  Listing(name: "platinum bling", startingBidPrice: 7.0, seller: c1, endDateTime: new Date() + 3, createdDateTime: new Date() - 3).save(failOnError: true);
                new  Listing(name: "copper bling", startingBidPrice: 6.0, seller: c1, endDateTime: new Date() + 2, createdDateTime: new Date() - 2).save(failOnError: true);
                new  Listing(name: "chrome bling", startingBidPrice: 5.0, seller: c1, endDateTime: new Date() + 1, createdDateTime: new Date() - 1).save(failOnError: true);
                new  Listing(name: "titanium bling", startingBidPrice: 4.0, seller: c1, endDateTime: new Date() + 2, createdDateTime: new Date() - 2).save(failOnError: true);
                new  Listing(name: "blue bling", startingBidPrice: 4.0, seller: c1, endDateTime: new Date() + 1, createdDateTime: new Date() - 1).save(failOnError: true);


                Listing l2 = new  Listing(name: "bike", startingBidPrice: 10.0, seller: c2, endDateTime: new Date() + 7, createdDateTime: new Date() - 7).save(failOnError: true);
                new  Listing(name: "red bike", startingBidPrice: 9.0, seller: c2, endDateTime: new Date() + 6, createdDateTime: new Date() - 6).save(failOnError: true);
                new  Listing(name: "blue bike", startingBidPrice: 8.0, seller: c2, endDateTime: new Date() + 5, createdDateTime: new Date() - 5).save(failOnError: true);
                new  Listing(name: "green bike", startingBidPrice: 7.0, seller: c2, endDateTime: new Date() + 4, createdDateTime: new Date() - 4).save(failOnError: true);
                new  Listing(name: "yellow bike", startingBidPrice: 6.0, seller: c2, endDateTime: new Date() + 3, createdDateTime: new Date() - 3).save(failOnError: true);
                new  Listing(name: "orange bike", startingBidPrice: 5.0, seller: c2, endDateTime: new Date() + 2, createdDateTime: new Date() - 2).save(failOnError: true);
                new  Listing(name: "black bike", startingBidPrice: 4.0, seller: c2, endDateTime: new Date() + 1, createdDateTime: new Date() - 1).save(failOnError: true);
                new  Listing(name: "brown bike", startingBidPrice: 3.0, seller: c2, endDateTime: new Date() + 1, createdDateTime: new Date() - 1).save(failOnError: true);
                new  Listing(name: "purple bike", startingBidPrice: 2.0, seller: c2, endDateTime: new Date() + 2, createdDateTime: new Date() - 2).save(failOnError: true);
                new  Listing(name: "white bike", startingBidPrice: 1.0, seller: c2, endDateTime: new Date() + 3, createdDateTime: new Date() - 3).save(failOnError: true);



                if (!Bid.count()) {
                    new Bid(customer: c1, listing: l1, amount: 12.0f, dateTime: new Date()).save(failOnError: true);
                    new Bid(customer: c2, listing: l2, amount: 12.0f, dateTime: new Date()).save(failOnError: true);
                }

            }


        }

    }
    def destroy = {
    }
}
